import 'package:xuance/bean/AiTypeCountBean.dart';
import 'package:xuance/bean/AiWarningitemBean.dart';
import 'package:xuance/bean/HomeAiWarnBean.dart';
import 'package:xuance/network/network_service.dart';

class AiWarningApi {
  static Future<AiWarningitemBean?> getList({
    required int page,
    required String startTime,
    required String endTime,
    required String queryCondition,
  }) async {
    var res = await NetworkService.post(
        url: "base-model-forecast-prd/queryBaseModelForecastPrdList",
        map: {
          "currentPage": page,
          "pageSize": 10,
          "startDate": startTime,
          "endDate": endTime,
          "queryCondition": queryCondition,
        },
        isShowLoading: false);
    return res.getTypedData((m) => AiWarningitemBean.fromJson(m));
  }

  static Future<String> getTcpFlow({
    required String esId,
    required String queryCondition,
  }) async {
    var res = await NetworkService.post(
        url: "/base-model-forecast-prd/queryBaseModelForecastPrdTcp",
        map: {'esId': esId, "queryCondition": queryCondition});
    return "${res.data['pcap_flow_text']}";
  }

  static Future<List<AiTypeCountBean>> getAiPredictFeature({
    required String startDate,
    required String endDate,
    required String queryCondition,
  }) async {
    var res = await NetworkService.post(
        url: "base-data-forecast/aiWarnTypeCount",
        map: {
          'startDate': startDate,
          'queryCondition': queryCondition,
          'endDate': endDate,
        },
        isShowLoading: false);
    return res.getTypedList((m) => AiTypeCountBean.fromJson(m)) ?? [];
  }

  static Future<List<HomeAiWarnBean>> aiPredice(
      {required String startTime,
      required String queryCondition,
      String? endTime,
      String? sip}) async {
    var map = {
      "startDate": startTime,
      "endDate": endTime,
      "queryCondition": queryCondition
    };
    if (sip != null) {
      map['sip'] = sip;
    }
    var res = await NetworkService.post(
        url: "base-model-forecast-prd/queryBaseModelForecastPrdGroup",
        map: map,
        isShowLoading: false);
    return res
            .getTypedList<HomeAiWarnBean>((m) => HomeAiWarnBean.fromJson(m)) ??
        [];
  }
}
